package engine;

public class Timer {
    private long ticks=0;
    /**Ticks after that number of milliseconds*/
    private long granularity=0;
    private boolean stopped;

    public Timer(int granularity) {
       this.granularity=granularity;
       this.stopped = false;
    }

    public void start() {
       ticks=System.currentTimeMillis();
       stopped = false;
    }

    public void reset() {
       start();
    }
    
    public void stop(){
    	stopped = true;
    }

    public long getElapsedTicks() {
    	if(stopped)
    		return 0;
       long cur=System.currentTimeMillis();
       long l=cur-ticks;

       if (l>=granularity) {
          ticks=cur-(l%granularity);
          return l/granularity;
       }
       return 0;
    }
 }
